import hashlib

import bcrypt


# 生成哈希值
def generate_has(password):
    hashed_password = bcrypt.hashpw(password, bcrypt.gensalt(10))
    return hashed_password


# 验证哈希值
def check_password(hashed_password, user_password):
    return bcrypt.checkpw(user_password, hashed_password)


def md5(data_string):
    # salt = "xxxxxxx"
    obj = hashlib.md5()
    obj.update(data_string.encode("utf-8"))
    return obj.hexdigest()



if __name__ == '__main__':
    # 示例
    password = b"my_secure_password"
    # password = bytes("my_secure_password", 'utf8')
    print(check_password(generate_has(password), password))
